package com.example.guiguihomemedical.controller;

import com.example.guiguihomemedical.common.Result;

import com.example.guiguihomemedical.entity.followup.FollowupWith;
import com.example.guiguihomemedical.service.FollowUpService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/followUp")
@CrossOrigin(origins ="*")
public class FollowUpController {
    @Autowired
    private FollowUpService followUpService;

    @GetMapping("/getOne")
    public Result getOneFollowupWith(@RequestParam(value = "id") Integer id) throws Exception {
        FollowupWith followupWith = followUpService.getOneFollowup(id);
        if (followupWith == null) {
            return
                    Result.success("无数据");
        } else return Result.success(followupWith);
    }
    @GetMapping("/getFollowUpType")
    public Result getOnesFollowUpType(@RequestParam( value = "idcard") String idcard){
        return Result.success(followUpService.getOnesFollowUpType(idcard));
    }

    @PostMapping("/addFollowUp")
    public Result add(@RequestBody FollowupWith followupWith) throws JsonProcessingException {

        return Result.success(followUpService.add(followupWith.getFollow(), followupWith.getObject()));
    }

    @GetMapping("/list")
    public Result list(@RequestParam(required = false, value = "PageBegin") Integer PageBegin,
                       @RequestParam(required = false, value = "PageSize") Integer PageSize,
                       @RequestParam(required = false, value = "timeLimit") String timeLimit,
                       @RequestParam(required = false, value = "dateA") String dateA,
                       @RequestParam(required = false, value = "dateB") String dateB,
                       @RequestParam(required = false, value = "state") Integer state,
                       @RequestParam(required = false, value = "type") String type,
                       @RequestParam(required = false, value = "searchString") String searchString) throws Exception {

        return Result.success(followUpService.findByPage(PageBegin, PageSize, timeLimit, dateA, dateB, state, type, searchString));
    }

    @PostMapping("/updateFollowUp")
    public Result update(@RequestBody FollowupWith followupWith) throws JsonProcessingException {
        return Result.success(followUpService.update(followupWith.getFollow(), followupWith.getObject()));
    }

    @PostMapping("/deleteFollowUp")
    public Result delete(@RequestBody FollowupWith followupWith) throws JsonProcessingException {
        return Result.success(followUpService.delete(followupWith.getFollow(), followupWith.getObject()));
    }

}
